import config from '../config/config.js';

const getIndexVideoList = async (userId)=>{
	return new Promise (async (resolve,reject)=>{
		let result = await uni.request({
			url:config.serverUrl+'/video/getVideoIndex',
			method:'GET'
		});
		if(result[1].data.status){
			resolve(result[1].data.videoList);
		} else {
			reject(result[1].data.content);
		}
	})
}

const produceMainList = (older,newer)=>{
	return new Promise (resolve=>{
		newer.forEach(item=>{
			item.videoCover = `${config.serverUrl}/${item.videoCover}`;
			if(older.length>8){
				older.shift();
			}
			older.push(item);
		})
	})
}

const produceSecList = (older,newer)=>{
	return new Promise (resolve=>{
		newer.forEach(item=>{
			older.push(item);
		})
	})
}


module.exports = {
	getIndexVideoList:getIndexVideoList,
	produceMainList:produceMainList,
	produceSecList:produceSecList
}